'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url admin/datas/kh/zhexiantu 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		const db = uniCloud.database();		
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			_
		} = util;
		let {
			uid,
			days
		} = data;
		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------
		if (days == 30) {
			let days30 = await db.collection('a_datas').where({
				type:1,
				agent_id: userInfo._id
			}).orderBy('_add_time', 'asc').field({
				drcz: true,
				drxh: true
			}).limit(30).get()

			let days30_cate = await db.collection('a_datas').where({
				type:1,
				agent_id: userInfo._id
			}).orderBy('_add_time', 'asc').field({
				date: true
			}).limit(30).get()
			res.categories = days30_cate.data
			res.datas = days30.data
		}

		if (days == 15) {
			let days15 = await db.collection('a_datas').where({
				type:1,
				agent_id: userInfo._id
			}).orderBy('_add_time', 'asc').field({
				drcz: true,
				drxh: true
			}).limit(15).get()

			let days15_cate = await db.collection('a_datas').where({
				type:1,
				agent_id: userInfo._id
			}).orderBy('_add_time', 'asc').field({
				date: true
			}).limit(15).get()
			res.categories = days15_cate.data
			res.datas = days15.data
		}

		if (days == 7) {
			let days7 = await db.collection('a_datas').where({
				type:1,
				agent_id: userInfo._id
			}).orderBy('_add_time', 'asc').field({
				drcz: true,
				drxh: true
			}).limit(7).get()
			let days7_cate = await db.collection('a_datas').where({
				type:1,
				agent_id: userInfo._id
			}).orderBy('_add_time', 'asc').field({
				date: true
			}).limit(7).get()
			res.categories = days7_cate.data
			res.datas = days7.data
		}



		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
